package be.cgi.heroesmanager.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import be.cgi.heroesmanager.R;
import be.cgi.heroesmanager.db.HeroesAdapter;
import be.cgi.heroesmanager.model.Hero;

public class DetailsActivity extends Activity {
	
	Hero currentHero;
	
	TextView tvName, tvCity, tvAbility;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_details);

		tvName = (TextView) findViewById(R.id.tvName);
		tvCity = (TextView) findViewById(R.id.tvCity);
		tvAbility = (TextView) findViewById(R.id.tvAbility);

		Bundle extra = getIntent().getExtras();
		if (extra != null) {
			long id = extra.getLong(HeroesAdapter.COLUMN_ID);

			HeroesAdapter adap = new HeroesAdapter(getApplicationContext());
			adap.openReadable();
			currentHero = adap.getOne(id);
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		
		if(currentHero != null){
			tvName.setText(currentHero.getName());
			tvCity.setText(currentHero.getCity());
			tvAbility.setText(currentHero.getAbility());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.details, menu);
		return true;
	}

}
